uniform mat4 ece_InvertModelViewMatrix;
uniform sampler2D texture;
uniform sampler2D eceGlPosition;
uniform sampler2D eceGlGameData;
uniform float decalSize;
varying vec4 vPosition;
void main() {
	vec2 vTexCoord = (vPosition.xy / vPosition.w + 1) / 2;
	vec4 gamedata = texture2D(eceGlGameData, vTexCoord);
	if(gamedata.r == 1.0) {
		vec4 position = texture2D(eceGlPosition, vTexCoord);
		position = ece_InvertModelViewMatrix * vec4(position.xyz, 1.0);
		if(position.z > decalSize) {
			discard;
		} else {
			float width = decalSize * 2.0;
			float x = (decalSize + position.x) / width;
			float y = (decalSize - position.y) / width;
			if(x < 0 || x > 1 || y < 0 || y > 1) {
				discard;
			} else {
				gl_FragColor = texture2D(texture, vec2(x, y));
			}
		}
	} else {
		discard;
	}
}